<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of VirtualStore
 *
 * @author LBerrocal
 */
class VirtualStore {

    static public function slugify($text) {
//        // replace non letter or digits by -
        $text = preg_replace('#[^\\pL\d]+#u', '-', $text);
//// trim
        $text = trim($text, '-');
//// transliterate
        if (function_exists('iconv')) {
            $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
        }
//// lowercase
        $text = strtolower($text);
//// remove unwanted characters
        $text = preg_replace('#[^-\w]+#', '', $text);
        if (empty($text)) {
            $text = 'n-a';
            //return $text;
        }
        return $text;
    }

    static function ageFrom($cdate, $dob) {
        if(!isset ($dob) || !isset ($cdate)){
            return 0;
        }
        list($Year, $Month, $Day) = explode("-", $dob);
        list($Year1, $Month1, $Day1) = explode("-", $cdate);

        $YearDiff = $Year1 - $Year;
        $DayDiff = $Day1 - $Day;
//        echo "**********************************\n";
//
//        echo "Year1:    " . $Year1 . "\n";
//        echo "Year:     " . $Year . "\n";
//        echo "YearDiff: " . $YearDiff . "\n";
//
//        echo "**********************************\n";
// If the birthday hasn't arrived yet this year, the person is one year younger

        if ($Month1 < $Month || ($Month1 == $Month && $Day1 < $DayDiff)) {

            $YearDiff--;
        }
        return $YearDiff;
    }

}

?>
